#include <iostream>
#include <cmath>

#define UPPER 1
#define LOWER 0
#define START .5

using namespace std;

double solve(double x, double upper, double lower, int p, int q, int r, int s, int t, int u) {
	double result = p*exp(-x) + q*sin(x) + r*cos(x) + s*tan(x) + t*x*x + u;
	double deriv = q*cos(x) - r*sin(x) + (1/cos(x))*(1/cos(x)) + 2*t*x -1;

	//Range has been minimized to final answer
	if(abs(upper - lower) <=.0001)
		return round(x*10000)/10000;

	if(result*deriv >= 0 ) 
		return solve((x+lower)/2, x, lower, p, q, r, s, t, u);
	else	
		return solve((upper+x)/2, upper, x, p, q, r, s, t, u);

	return -1;
}

void solve(int p, int q, int r, int s, int t, int u) {
	double x = solve(START, UPPER, LOWER, p, q, r, s, t, u);
	double result = p*exp(-x) + q*sin(x) + r*cos(x) + s*tan(x) + t*x*x + u;

	if (result < 0.001)
		cout << x << endl;
	else
		cout << "No Solution" << endl;
}

using namespace std;

int main(void) {
	cout << "John Gehrig Lafayette College" << endl;
	cout << "   September 19, 2013" << endl;
	cout << "   Problem 10341: Solve It!" << endl;
	cout << "   Programing Comp Practice" << endl;

	cout << endl << "NOTE: Values are NOT accepted from stdin," << endl;
	cout << "      they are hard coded instead. " << endl << endl;

	solve(0,0,0,0,-2,1);
	solve(1,0,0,0,-1,2);
	solve(1,-1,1,-1,-1,1);
	return 0;
}
